#include "helper/sqlite/shortcut/Executor.h"


#include "helper/sqlite/IDB.h"
#include "helper/sqlite/Statement.h"
#include "helper/sqlite/ExecutionResult.h"

namespace helper {
namespace sqlite {
namespace shortcut {

Executor::Executor(IDB & db)
  : DBWrapper(db)
{
}
Executor::~Executor() {
}


ExecutionResult Executor::execute(const std::string & sql,  const fbind_type & fbind) {
  std::error_code ec;
  auto && stmt = db().createStatement(sql, ec);
  if(!ec && stmt) {
    if(fbind){
      if(auto && ec = stmt->prepareInput(fbind); ec){
        return ExecutionResult::make_error(ec);
      }
    }
    return stmt->execute();
  }
  return ExecutionResult(ec, &db());
}


}//namespace shortcut
}//namespace sqlite
}//namespace helper
